/*
 * @Author: 晴鸢. 3013433857@qq.com
 * @Date: 2025-11-03 12:28:20
 * @LastEditors: 晴鸢. 3013433857@qq.com
 * @LastEditTime: 2025-11-03 12:55:37
 * @FilePath: /Learn/WebCalculator/testjson/test.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<json/json.h>
#include<unistd.h>
int main()
{
    //Json中value是一个k-v结构的变量
    //序列化
    Json::Value root;
    root["x"]=100;
    root["y"]=200;
    root["op"]='+';
    root["desc"]="this is a + oper";

    Json::StyledWriter w;
    std::string res=w.write(root);
    std::cout<<res<<std::endl;
    sleep(1);
    //反序列化
    Json::Value v;
    Json::Reader r;
    r.parse(res,v);

    int x=v["x"].asInt();
    int y=v["y"].asInt();
    char op=v["op"].asInt();
    std::string desc=v["desc"].asString();

    std::cout<<x<<std::endl;
    std::cout<<y<<std::endl;
    std::cout<<op<<std::endl;
    std::cout<<desc<<std::endl;
    return 0;
}